<template>
  <el-dialog
    append-to-body
    :visible.sync="visible"
    title="拒绝说明"
    :before-close="beforeClose"
    :close-on-click-modal="false"
  >
    <div class="d-flex align-items-center mb-3">
      <div>拒绝人：</div>
      <div>
        {{ rejectName }}
      </div>
    </div>
    <div class="d-flex">
      <div>项目拒绝理由：</div>
      <div class="form-control-ml">
        <el-input
          v-model="confuse_des"
          rows="5"
          placeholder="输入拒绝理由"
          type="textarea"
        ></el-input>
      </div>
    </div>
    <div class="text-center mt-2">
      <el-button @click="handleReject" type="primary" :loading="submitLoading" class="btn-long">
        完成
      </el-button>
      <el-button @click="beforeClose" class="btn-long">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  components: {},
  props: {
    visible: Boolean,
    queryId: String,
  },
  data() {
    return {
      confuse_des: '',
      submitLoading: false,
      tableName: 'customer_related',
    }
  },
  computed: {
    ...mapGetters(['org', 'user', 'userId']),
    rejectName() {
      return this.org.orgName + '-' + this.user.realName
    },
  },
  watch: {},
  mounted() {},
  created() {},
  methods: {
    beforeClose() {
      this.confuse_des = ''
      this.$emit('update:visible', false)
    },
    setStatus(num) {
      const data = {}
      data.res_status = num
      data.res_date = this.$utils.dateFormat(new Date())
      data.res_person = this.user.realName
      data.res_option = this.confuse_des
      return data
    },
    handleReject() {
      if (!this.confuse_des) {
        return this.$message.warning('请输入拒绝原因')
      }
      const data = this.setStatus(2)
      this.$utils
        .msgbox({
          message: `确定拒绝?`,
          type: 'error',
          beforeClose: () =>
            this.$api.updateData(this.$serviceName, this.tableName, this.queryId, data),
        })
        .then(() => {
          this.beforeClose()
          this.$message.success('操作成功！')
          this.$emit('success', false)
        })
        .catch(() => this.$message.error(`操作失败，请重试！`))
    },
  },
}
</script>
<style lang="scss" scoped></style>
